import { createWebHistory, createRouter } from 'vue-router'
/* Layout */
import Layout from '@/layout/index.vue'

/**
 * Note: 路由配置项
 *
 * hidden: true                     // 当设置 true 的时候该路由不会再侧边栏出现 如401，login等页面，或者如一些编辑页面/edit/1
 * alwaysShow: true                 // 当你一个路由下面的 children 声明的路由大于1个时，自动会变成嵌套的模式--如组件页面
 *                                  // 只有一个时，会将那个子路由当做根路由显示在侧边栏--如引导页面
 *                                  // 若你想不管路由下面的 children 声明的个数都显示你的根路由
 *                                  // 你可以设置 alwaysShow: true，这样它就会忽略之前定义的规则，一直显示根路由
 * redirect: noRedirect             // 当设置 noRedirect 的时候该路由在面包屑导航中不可被点击
 * name:'router-name'               // 设定路由的名字，一定要填写不然使用<keep-alive>时会出现各种问题
 * query: '{"id": 1, "name": "ry"}' // 访问路由的默认传递参数
 * roles: ['admin', 'common']       // 访问路由的角色权限
 * permissions: ['a:a:a', 'b:b:b']  // 访问路由的菜单权限
 * meta : {
    noCache: true                   // 如果设置为true，则不会被 <keep-alive> 缓存(默认 false)
    title: 'title'                  // 设置该路由在侧边栏和面包屑中展示的名字
    icon: 'svg-name'                // 设置该路由的图标，对应路径src/assets/icons/svg
    breadcrumb: false               // 如果设置为false，则不会在breadcrumb面包屑中显示
    activeMenu: '/system/user'      // 当路由设置了该属性，则会高亮相对应的侧边栏。
  }
 */

// 公共路由
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index.vue')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index.vue'),
    hidden: true
  },
  {
    path: "/:pathMatch(.*)*",
    component: () => import('@/views/error/404.vue'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error/401.vue'),
    hidden: true
  },
  {
    path: '/agreement',
    component: () => import('@/views/agreement.vue'),
    hidden: true
  },
  {
    path: '/privacy',
    component: () => import('@/views/privacy.vue'),
    hidden: true
  },
  {
    path: '',
    component: Layout,
    redirect: '/index',
    children: [
      {
        path: '/index',
        component: () => import('@/views/index.vue'),
        name: 'Index',
        meta: { title: '工作台', icon: 'dashboard', affix: true }
      },
      {
        path: '/project/mine/create',
        component: () => import('@/views/project/mine/create.vue'),
        name: 'MyProjectCreate',
        meta: { title: '新建项目', activeMenu: '/project/mine/create' }
      },
      {
        path: '/project/mine/edit',
        component: () => import('@/views/project/mine/edit.vue'),
        name: 'MyProjectEdit',
        meta: { title: '编辑项目', activeMenu: '/project/mine/edit' }
      },
      {
        path: '/project/mine/initiateChange',
        component: () => import('@/views/project/mine/initiateChange.vue'),
        name: 'InitiateChange',
        meta: { title: '项目变更', activeMenu: '/project/mine/initiateChange' }
      },
      {
        path: '/project/mine/submitBudget',
        component: () => import('@/views/project/mine/submitBudget.vue'),
        name: 'SubmitBudget',
        meta: { title: '提交预算', activeMenu: '/project/mine/submitBudget' }
      },
      {
        path: '/project/mine/submitIntermediateInspection',
        component: () => import('@/views/project/mine/submitIntermediateInspection.vue'),
        name: 'SubmitIntermediateInspection',
        meta: { title: '提交中检', activeMenu: '/project/mine/submitIntermediateInspection' }
      },
      {
        path: '/project/mine/submitConclusion',
        component: () => import('@/views/project/mine/submitConclusion.vue'),
        name: 'SubmitConclusion',
        meta: { title: '提交结项', activeMenu: '/project/mine/submitConclusion' }
      },

    ]
  },
  {
    path: '/resultsManagement',
    component: Layout,
    hidden: true,
    redirect: 'noredirect',
    children: [
      {
        path: 'college/college-academic-paper/detail',
        component: () => import('@/views/resultsManagement/college/college-academic-paper/detail.vue'),
        name: 'college-academic-paper-detail',
        meta: { title: '学术论文详情' }
      },
      {
        path: 'office/office-academic-paper/detail',
        component: () => import('@/views/resultsManagement/office/office-academic-paper/detail.vue'),
        name: 'office-academic-paper-detail',
        meta: { title: '学术论文详情' }
      },
      {
        path: 'mine/mine-academic-paper/detail',
        component: () => import('@/views/resultsManagement/mine/mine-academic-paper/detail.vue'),
        name: 'mine-academic-paper-detail',
        meta: { title: '学术论文详情' }
      },
      {
        path: 'college/college-academic-work/detail',
        component: () => import('@/views/resultsManagement/college/college-academic-work/detail.vue'),
        name: 'college-academic-work-detail',
        meta: { title: '学术著作详情' }
      },
      {
        path: 'office/office-academic-work/detail',
        component: () => import('@/views/resultsManagement/office/office-academic-work/detail.vue'),
        name: 'office-academic-work-detail',
        meta: { title: '学术著作详情' }
      },
      {
        path: 'mine/mine-academic-work/detail',
        component: () => import('@/views/resultsManagement/mine/mine-academic-work/detail.vue'),
        name: 'mine-academic-work-detail',
        meta: { title: '学术著作详情' }
      },
      {
        path: 'college/college-patent/detail',
        component: () => import('@/views/resultsManagement/college/college-patent/detail.vue'),
        name: 'college-patent-detail',
        meta: { title: '专利/软著详情' }
      },
      {
        path: 'office/office-patent/detail',
        component: () => import('@/views/resultsManagement/office/office-patent/detail.vue'),
        name: 'office-patent-detail',
        meta: { title: '专利/软著详情' }
      },
      {
        path: 'mine/mine-patent/detail',
        component: () => import('@/views/resultsManagement/mine/mine-patent/detail.vue'),
        name: 'mine-patent-detail',
        meta: { title: '专利/软著详情' }
      },
      {
        path: 'college/college-vertical/detail',
        component: () => import('@/views/resultsManagement/college/college-vertical/detail.vue'),
        name: 'college-vertical-detail',
        meta: { title: '纵向项目管理详情' }
      },
      {
        path: 'office/office-vertical/detail',
        component: () => import('@/views/resultsManagement/office/office-vertical/detail.vue'),
        name: 'office-vertical-detail',
        meta: { title: '纵向项目管理详情' }
      },
      {
        path: 'mine/mine-vertical/detail',
        component: () => import('@/views/resultsManagement/mine/mine-vertical/detail.vue'),
        name: 'mine-vertical-detail',
        meta: { title: '纵向项目详情' }
      },

      {
        path: 'college/college-horizontal/detail',
        component: () => import('@/views/resultsManagement/college/college-horizontal/detail.vue'),
        name: 'college-horizontal-detail',
        meta: { title: '横向项目管理详情' }
      },
      {
        path: 'office/office-horizontal/detail',
        component: () => import('@/views/resultsManagement/office/office-horizontal/detail.vue'),
        name: 'office-horizontal-detail',
        meta: { title: '横向项目管理详情' }
      },
      {
        path: 'mine/mine-horizontal/detail',
        component: () => import('@/views/resultsManagement/mine/mine-horizontal/detail.vue'),
        name: 'mine-horizontal-detail',
        meta: { title: '横向项目详情' }
      },
      {
        path: 'college/college-guide-student/detail',
        component: () => import('@/views/resultsManagement/college/college-guide-student/detail.vue'),
        name: 'college-guide-student-detail',
        meta: { title: '指导学生科研项目结项管理详情' }
      },
      {
        path: 'office/office-guide-student/detail',
        component: () => import('@/views/resultsManagement/office/office-guide-student/detail.vue'),
        name: 'office-guide-student-detail',
        meta: { title: '指导学生科研项目结项管理详情' }
      },
      {
        path: 'mine/mine-guide-student/detail',
        component: () => import('@/views/resultsManagement/mine/mine-guide-student/detail.vue'),
        name: 'mine-guide-student-detail',
        meta: { title: '指导学生科研项目结项详情' }
      },
      {
        path: 'college/college-laboratory/detail',
        component: () => import('@/views/resultsManagement/college/college-laboratory/detail.vue'),
        name: 'college-laboratory-detail',
        meta: { title: '重点实验室/科研团队立项/结项管理详情' }
      },
      {
        path: 'office/office-laboratory/detail',
        component: () => import('@/views/resultsManagement/office/office-laboratory/detail.vue'),
        name: 'office-laboratory-detail',
        meta: { title: '重点实验室/科研团队立项/结项管理详情' }
      },
      {
        path: 'mine/mine-laboratory/detail',
        component: () => import('@/views/resultsManagement/mine/mine-laboratory/detail.vue'),
        name: 'mine-laboratory-detail',
        meta: { title: '重点实验室/科研团队立项/结项详情' }
      },
      {
        path: 'college/college-research-award/detail',
        component: () => import('@/views/resultsManagement/college/college-research-award/detail.vue'),
        name: 'college-research-award-detail',
        meta: { title: '科研获奖详情' }
      },
      {
        path: 'office/office-research-award/detail',
        component: () => import('@/views/resultsManagement/office/office-research-award/detail.vue'),
        name: 'office-research-award-detail',
        meta: { title: '科研获奖详情' }
      },
      {
        path: 'mine/mine-research-award/detail',
        component: () => import('@/views/resultsManagement/mine/mine-research-award/detail.vue'),
        name: 'mine-research-award-detail',
        meta: { title: '科研获奖详情' }
      },
      {
        path: 'college/college-sports-competition/detail',
        component: () => import('@/views/resultsManagement/college/college-sports-competition/detail.vue'),
        name: 'college-sports-competition-detail',
        meta: { title: '体育竞赛详情' }
      },
      {
        path: 'office/office-sports-competition/detail',
        component: () => import('@/views/resultsManagement/office/office-sports-competition/detail.vue'),
        name: 'office-sports-competition-detail',
        meta: { title: '体育竞赛详情' }
      },
      {
        path: 'mine/mine-sports-competition/detail',
        component: () => import('@/views/resultsManagement/mine/mine-sports-competition/detail.vue'),
        name: 'mine-sports-competition-detail',
        meta: { title: '体育竞赛详情' }
      },
      {
        path: 'college/college-other/detail',
        component: () => import('@/views/resultsManagement/college/college-other/detail.vue'),
        name: 'college-other-detail',
        meta: { title: '其他成果详情' }
      },
      {
        path: 'office/office-other/detail',
        component: () => import('@/views/resultsManagement/office/office-other/detail.vue'),
        name: 'office-other-detail',
        meta: { title: '其他成果详情' }
      },
      {
        path: 'mine/mine-other/detail',
        component: () => import('@/views/resultsManagement/mine/mine-other/detail.vue'),
        name: 'mine-other-detail',
        meta: { title: '其他成果详情' }
      },

    ]
  },
  {
    path: '/achievementReward/assessmentReward',
    component: Layout,
    hidden: true,
    permissions: ['researchReward:rewardResult:list'],
    children: [
      {
        path: 'researchAssessment/assessmentResult',
        component: () => import('@/views/achievementReward/assessmentReward/researchAssessment/assessmentResult.vue'),
        name: 'AssessmentResult',
        meta: { title: '统计结果', activeMenu: '/achievementReward/assessmentReward/researchAssessment/assessmentResult' }
      },
      {
        path: 'managerWay/detail',
        component: () => import('@/views/achievementReward/assessmentReward/managerWay/detail.vue'),
        name: 'ManagerWayDetail',
        meta: { title: '管理办法详情', activeMenu: '/achievementReward/assessmentReward/managerWay/detail' }
      },
      {
        path: 'researchReward/rewardResult',
        component: () => import('@/views/achievementReward/assessmentReward/researchReward/rewardResult.vue'),
        name: 'RewardResult',
        meta: { title: '奖励结果', activeMenu: '/achievementReward/assessmentReward/researchReward/rewardResult' }
      },
      {
        path: 'rewardWay/detail',
        component: () => import('@/views/achievementReward/assessmentReward/rewardWay/detail.vue'),
        name: 'RewardWayDetail',
        meta: { title: '奖励办法详情', activeMenu: '/achievementReward/assessmentReward/rewardWay/detail' }
      },
    ]
  },
  {
    path: '/achievementReward',
    component: Layout,
    hidden: true,
    redirect: 'noredirect',
    children: [
      {
        path: 'myResearchPoint/details',
        component: () => import('@/views/achievementReward/myResearchPoint/details/index.vue'),
        name: 'myResearchPointDetails',
        meta: { title: '科研积分详情' }
      },
    ]
  },
  {
    path: '/achievementReward',
    component: Layout,
    hidden: true,
    redirect: 'noredirect',
    children: [
      {
        path: 'personalRewardPoint/details',
        component: () => import('@/views/achievementReward/personalRewardPoint/details/index.vue'),
        name: 'personalRewardPointDetails',
        meta: { title: '我的奖励积分详情' }
      },
    ]
  },
  {
    path: '/user',
    component: Layout,
    hidden: true,
    redirect: 'noredirect',
    children: [
      {
        path: 'profile',
        component: () => import('@/views/system/user/profile/index.vue'),
        name: 'Profile',
        meta: { title: '个人信息', icon: 'user' }
      }
    ]
  },
  {
    path: '/home',
    component: Layout,
    hidden: true,
    redirect: 'noredirect',
    children: [
      {
        path: 'noticeList',
        component: () => import('@/views/home/noticeList/index.vue'),
        name: 'NoticeList',
        meta: { title: '通知公告' }
      }
    ]
  },
  {
    path: '/system',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'dict/data',
        component: () => import('@/views/system/dict/data/index.vue'),
        name: 'Data',
        meta: { title: '字典数据'}
      }
    ]
  },
  
]

// 动态路由，基于用户权限动态去加载
export const dynamicRoutes = [
  {
    path: '/project',
    component: Layout,
    permissions: ['project:manage:list'],
    hidden: true,
    children: [
      {
        path: 'index/:jobId(\\d+)',
        component: () => import('@/views/project/manage/index.vue'),
        name: 'ProjectManage',
        meta: { title: '项目管理', activeMenu: '/project/manage/index' }
      },
      {
        path: 'manage/publishNotices',
        component: () => import('@/views/project/manage/publishNotices.vue'),
        name: 'publishNotices',
        meta: { title: '发布申报通知', activeMenu: '/project/manage/publishNotices' }
      },
      {
        path: 'manage/noticesDetails',
        component: () => import('@/views/project/manage/noticesDetails.vue'),
        name: 'noticesDetails',
        meta: { title: '消息通知详情', activeMenu: '/project/manage/noticesDetails' }
      },
      {
        path: 'manage/details',
        component: () => import('@/views/project/manage/details.vue'),
        name: 'ManagerDetail',
        meta: { title: '项目详情', activeMenu: '/project/manage/details' }
      },
      {
        path: 'manage/budgetReview',
        component: () => import('@/views/project/manage/budgetReview.vue'),
        name: 'ManagerBudgetReview',
        meta: { title: '预算审核', activeMenu: '/project/manage/budgetReview' }
      },
      {
        path: 'intermediateInspection/details',
        component: () => import('@/views/project/intermediateInspection/details.vue'),
        name: 'IntermediateInspectionDetail',
        meta: { title: '项目详情', activeMenu: '/project/intermediateInspection/details' }
      },
      {
        path: 'intermediateInspection/intermediateInspectionReview',
        component: () => import('@/views/project/intermediateInspection/review.vue'),
        name: 'IntermediateInspectionReview',
        meta: { title: '中检审核', activeMenu: '/project/intermediateInspection/review' }
      },
      {
        path: 'conclusion/details',
        component: () => import('@/views/project/conclusion/details.vue'),
        name: 'ConclusionDetail',
        meta: { title: '项目详情', activeMenu: '/project/conclusion/details' }
      },
      {
        path: 'conclusion/conclusionReview',
        component: () => import('@/views/project/conclusion/review.vue'),
        name: 'ConclusionReview',
        meta: { title: '结项审核', activeMenu: '/project/conclusion/review' }
      },
      {
        path: 'manage/ConclusionWaitApproval',
        component: () => import('@/views/project/manage/ConclusionWaitApproval.vue'),
        name: 'ConclusionWaitApproval',
        meta: { title: '结项初审', activeMenu: '/project/manage/ConclusionWaitApproval' }
      },
      {
        path: 'change/details',
        component: () => import('@/views/project/change/details.vue'),
        name: 'ChangeDetail',
        meta: { title: '项目详情', activeMenu: '/project/change/details' }
      },
      {
        path: 'change/changeReview',
        component: () => import('@/views/project/change/review.vue'),
        name: 'ChangeReview',
        meta: { title: '变更审核', activeMenu: '/project/change/review' }
      },
      {
        path: 'manage/notices',
        component: () => import('@/views/project/manage/notices.vue'),
        name: 'ManageNotices',
        meta: { title: '项目申报', activeMenu: '/project/manage/notices' }
      },
      {
        path: 'manage/publicList',
        component: () => import('@/views/project/manage/publicList.vue'),
        name: 'ManagePublicList',
        meta: { title: '项目申报列表', activeMenu: '/project/manage/publicList' }
      },
    ]
  },
  {
    path: '/project/mine',
    component: () => import('@/views/project/mine/index.vue'),
    name: 'MyProject',
    meta: { title: '我的项目', activeMenu: '/project/mine/index' },
  },
  {
    path: '/achievementReward/assessmentReward',
    component: Layout,
    hidden: true,
    permissions: ['researchReward:rewardResult:list'],
    children: [
      {
        path: 'researchAssessment/assessmentResult',
        component: () => import('@/views/achievementReward/assessmentReward/researchAssessment/assessmentResult.vue'),
        name: 'AssessmentResult',
        meta: { title: '统计结果', activeMenu: '/achievementReward/assessmentReward/researchAssessment/assessmentResult' }
      },
      {
        path: 'researchAssessment/personalPointDetail',
        component: () => import('@/views/achievementReward/assessmentReward/researchAssessment/personalPointDetail.vue'),
        name: 'PersonalPointDetail',
        meta: { title: '个人积分详情', activeMenu: '/achievementReward/assessmentReward/researchAssessment/personalPointDetail' }
      },
      {
        path: 'managerWay/detail',
        component: () => import('@/views/achievementReward/assessmentReward/managerWay/detail.vue'),
        name: 'ManagerWayDetail',
        meta: { title: '管理办法详情', activeMenu: '/achievementReward/assessmentReward/managerWay/detail' }
      },
      {
        path: 'researchReward/rewardResult',
        component: () => import('@/views/achievementReward/assessmentReward/researchReward/rewardResult.vue'),
        name: 'RewardResult',
        meta: { title: '奖励结果', activeMenu: '/achievementReward/assessmentReward/researchReward/rewardResult' }
      },
      {
        path: 'researchReward/rewardDetail',
        component: () => import('@/views/achievementReward/assessmentReward/researchReward/rewardDetail.vue'),
        name: 'RewardDetail',
        meta: { title: '奖励详情', activeMenu: '/achievementReward/assessmentReward/researchReward/rewardDetail' }
      },
      {
        path: 'rewardWay/detail',
        component: () => import('@/views/achievementReward/assessmentReward/rewardWay/detail.vue'),
        name: 'RewardWayDetail',
        meta: { title: '奖励办法详情', activeMenu: '/achievementReward/assessmentReward/rewardWay/detail' }
      },
    ]
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes: constantRoutes,
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return { top: 0 }
    }
  },
});

export default router;
